// BingoTouch Develop Debug
// Yuxg@bingosoft.net	2012.6

// 显示PC端的BTSelect对话框
function showPCSelect(id,selectedIndex,data,callback){
	var json = eval("(" + data + ")");
	
	var wid = "btSelectWin";
	
	var html = "";
	html += "<div style='width:200px;padding:10px;'><li style='font-size:14px;'>" + json.title + "</li><br>";
	html += "<select id='" + wid + "select' style='width:180px'>";
	for(var i=0;i<json.data.length;i++){
		html += "<option value='" + json.data[i].value + "'>" + json.data[i].text + "</option>";
	}
	html += "</select>";
	html += "<br><input type=button value='确定' onclick=selected('" + wid + "','" +id+ "','" + callback+ "');><input type=button value='取消' onclick=closeWin('" + wid + "');>";
	html += "";
	html += "</div>";
	
	var w = 200;
	var h = 100;
	var t = window.document.body.scrollTop + parseInt((parseInt(window.document.body.clientHeight)-h)/2);
	var l = parseInt((parseInt(window.document.body.clientWidth)-w)/2);
	var a = new xWin(wid,w,h,l,t,html);
}
function selected(wid, id, callback)
{
	var sel = document.all(wid + "select"); 
	if (sel != null && sel.options[sel.selectedIndex] != null){
		var data = {"text":sel.options[sel.selectedIndex].text,"value":sel.options[sel.selectedIndex].value};
		eval(callback + "('" +id+ "'," +sel.selectedIndex+ " ,data);");
	}
	closeWin(wid);
}

// 显示PC端的日期选择控件
function showPCDateSelect(id,value,data,callback){
	var json = eval("(" + data + ")");
	if (value == "" || value == null){
		var curDate = new Date();
		value = curDate.getFullYear() + "-" + (curDate.getMonth()+1) + "-" + curDate.getDate();
	}
	var wid = "btDateWin";
	
	
	
	var html = "";
	html += "<div style='width:200px;padding:10px;'><li style='font-size:14px;'>" + json.title + "</li><br>";
	html += "<input type=text value='" + value + "'  id='" + wid + "DateSelect' style='width:180px'>";
	html += "<br><input type=button value='确定' onclick=dateSelected('" + wid + "','" +id+ "','" + callback+ "');><input type=button value='取消' onclick=closeWin('" + wid + "');>";
	html += "";
	html += "</div>";
	
	var w = 200;
	var h = 100;
	var t = window.document.body.scrollTop + parseInt((parseInt(window.document.body.clientHeight)-h)/2);
	var l = parseInt((parseInt(window.document.body.clientWidth)-w)/2);
	var a = new xWin(wid,w,h,l,t,html);
}
function dateSelected(wid, id, callback)
{
	var dateInput = document.all(wid + "DateSelect"); 
	if (dateInput != null){
		eval(callback + "('" +id+ "','" +dateInput.value+ "');");
	}
	closeWin(wid);
}
//PC对话框
function xWin(id,w,h,l,t,msg,index)
{
 this.id      = id;
 this.width   = w;
 this.height  = h;
 this.left    = l;
 this.top     = t;
 this.zIndex  = index;
 this.message = msg;
 this.bulid   = bulid;
 this.bulid();
}
//初始化;
function bulid()
{ 
 var str = ""
  + "<div id=BT" + this.id + " "
  + "style='border-radius:15px;padding:10px;"
  + "z-index:" + this.zIndex + ";"
  + "width:" + this.width + "px;"
  + "height:" + this.height + "px;"
  + "left:" + this.left + "px;"
  + "top:" + this.top + "px;"
  + "background-color:white;"
  + "color:black;"
  + "font-size:10px;"
  + "font-family:Verdana;"
  + "position:absolute;"
  + "cursor:default;"
  + "border:2px solid gray;"
  + "'>" + this.message
  + "</div>";  
 document.body.insertAdjacentHTML("beforeEnd",str);
}
function closeWin(id){
	var win = document.all("BT"+id); 
	if (win != null)
		document.body.removeChild(win);
}
